package online.longzipeng.modules.user.service.impl;

import online.longzipeng.commons.dynamic.datasource.annotation.DataSource;
import online.longzipeng.modules.user.entity.User;
import online.longzipeng.modules.user.mapper.UserMapper;
import online.longzipeng.modules.user.service.UserService;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: lzp
 * @description:
 * @Date: 2023/2/19
 */
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;


	@DataSource("lzp1")
	@Override
	public void testDynamicDatasources() {
		User user = userMapper.getUser();
		System.out.println(user.getNickName());

		UserServiceImpl userService = (UserServiceImpl) AopContext.currentProxy();
		userService.test2();
	}

	@DataSource("lzp2")
	public void test2() {
		User user = userMapper.getUser();
		System.out.println(user.getNickName());

		UserServiceImpl userService = (UserServiceImpl) AopContext.currentProxy();
		userService.test3();
	}

	@DataSource("lzp3")
	public void test3() {
		User user = userMapper.getUser();
		System.out.println(user.getNickName());
	}

}
